package com.asiainfo.dao;
/*
 * 
 * 教练数据库操作类
 */
import java.sql.ResultSet;
import java.sql.SQLException;

import com.asiainfo.bean.Coach;
import com.asiainfo.database.JdbcTemplete;
import com.asiainfo.database.ResultSetHandler;

public class Coach_Dao {
	//添加教练
	public int addcoach(Coach coach){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "insert into coach(coach_name,coach_home,coach_age,coach_speciality) values (?,?,?,?)";
		return jt.update(sql, coach.getCoach_name(),coach.getCoach_home(),coach.getCoach_age(),coach.getCoach_speciality());
	}
	//根据名字查找教练
	public Coach findcoachByName(String coachname){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select coach_name,coach_home,coach_speciality,coach_age,coach_id from coach where coach_name=?";
		Coach coach = (Coach) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				Coach coach = null;
				if (rs.next()) {
					coach = new Coach();
					coach.setCoach_name(rs.getString(1));
					coach.setCoach_home(rs.getString(2));
					coach.setCoach_speciality(rs.getString(3));
					coach.setCoach_age(rs.getInt(4));
					coach.setCoach_id(rs.getInt(5));
				}
				return coach;
			}
		}, coachname);
		return coach;
	}
	//根据ID查找教练
	public Coach findcoachById(int id){
		JdbcTemplete jt = new JdbcTemplete();
		String sql = "select coach_name,coach_home,coach_speciality,coach_age,coach_id from coach where coach_id=?";
		Coach coach = (Coach) jt.quary(sql, new ResultSetHandler() {
			public Object doHandler(ResultSet rs) throws SQLException {
				Coach coach = null;
				if (rs.next()) {
					coach = new Coach();
					coach.setCoach_name(rs.getString(1));
					coach.setCoach_home(rs.getString(2));
					coach.setCoach_speciality(rs.getString(3));
					coach.setCoach_age(rs.getInt(4));
					coach.setCoach_id(rs.getInt(5));
				}
				return coach;
			}
		}, id);
		return coach;
	}
}
